package com.ruoyi.plot.service.impl;

import com.ruoyi.common.filter.ID;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.plot.domain.AtbPlotDetail;
import com.ruoyi.plot.dto.request.StatusDto;
import com.ruoyi.plot.mapper.AtbPlotDetailMapper;
import com.ruoyi.plot.service.IAtbPlotDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 小区详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-14
 */
@Service
public class AtbPlotDetailServiceImpl implements IAtbPlotDetailService 
{
    @Autowired
    private AtbPlotDetailMapper atbPlotDetailMapper;

    /**
     * 查询小区详情
     * 
     * @param plotId 小区详情主键
     * @return 小区详情
     */
    @Override
    public AtbPlotDetail selectAtbPlotDetailByPlotId(Long plotId)
    {
        return atbPlotDetailMapper.selectAtbPlotDetailByPlotId(plotId);
    }

    /**
     * 查询小区详情列表
     * 
     * @param atbPlotDetail 小区详情
     * @return 小区详情
     */
    @Override
    public List<AtbPlotDetail> selectAtbPlotDetailList(AtbPlotDetail atbPlotDetail)
    {
        return atbPlotDetailMapper.selectAtbPlotDetailList(atbPlotDetail);
    }

    /**
     * 新增小区详情
     * 
     * @param atbPlotDetail 小区详情
     * @return 结果
     */
    @Override
    public int insertAtbPlotDetail(AtbPlotDetail atbPlotDetail)
    {
        atbPlotDetail.setCreateTime(DateUtils.getNowDate());
        atbPlotDetail.setPlotId(new ID().getId()/2);
        atbPlotDetail.setIsExamine(0L);
        atbPlotDetail.setIsPutaway(0L);
        return atbPlotDetailMapper.insertAtbPlotDetail(atbPlotDetail);
    }

    /**
     * 修改小区详情
     *
     * @param atbPlotDetail 小区详情
     * @return 结果
     */
    @Override
    public int updateAtbPlotDetail(AtbPlotDetail atbPlotDetail)
    {
        return atbPlotDetailMapper.updateAtbPlotDetail(atbPlotDetail);
    }

    /**
     * 修改小区状态
     *
     * @param statusDto 小区状态
     * @return 结果
     */
    @Override
    public int updateStatus(StatusDto statusDto)
    {
        if (statusDto.getMes().equals("审核")) {
    //        atbPlotDetailMapper.updateAtbPlotExamineStatus(statusDto);
           return atbPlotDetailMapper.updateExamineStatus(statusDto);
        }

        if (statusDto.getMes().equals("上下架")) {
        //    atbPlotDetailMapper.updateAtbPlotPutawayStatus(statusDto);
            return atbPlotDetailMapper.updatePutawayStatus(statusDto);
        }

        return -1;
    }

    /**
     * 批量删除小区详情
     * 
     * @param plotIds 需要删除的小区详情主键
     * @return 结果
     */
    @Override
    public int deleteAtbPlotDetailByPlotIds(Long[] plotIds)
    {
        return atbPlotDetailMapper.deleteAtbPlotDetailByPlotIds(plotIds);
    }

    /**
     * 删除小区详情信息
     * 
     * @param plotId 小区详情主键
     * @return 结果
     */
    @Override
    public int deleteAtbPlotDetailByPlotId(Long plotId)
    {
        return atbPlotDetailMapper.deleteAtbPlotDetailByPlotId(plotId);
    }
}
